<?php
namespace App\Providers\VersionTraits;

use App\Jobs\UnpreparedSqlExecute;
use App\Models\Meta\WxPostMetaStr;
use App\Models\Posts\WxPost;
use App\Models\Shop\WxShopCart;
use App\Models\Shop\WxShopGoods;
use App\Models\System\PermissionMenu;
use App\Models\User\WxUser;
use App\Models\User\WxUserSetting;
use App\Wen\Utils\Settings;
use Dcat\Admin\Models\AdminSubMenu;
use Dcat\Admin\Models\Menu;
use Dcat\Admin\Models\Permission;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

trait _1_1_10_trait{

    function _v1_1_0_1()
    {
        if (_empty_(Settings::get('app_user_about_mine_list'))){
            Settings::set('app_user_about_mine_list', '[{"name":"\u5e2e\u52a9\u4e0e\u53cd\u9988","type":"6","target":"\/pages\/help\/feedbackIndex\/feedbackIndex"},{"name":"\u9690\u79c1\u653f\u7b56","type":"6","target":"\/pages\/common\/clause?type=22"},{"name":"\u7528\u6237\u534f\u8bae","type":"6","target":"\/pages\/common\/clause?type=21"},{"name":"\u5145\u7535\u58f0\u660e","type":"6","target":"\/pages\/common\/clause?type=24"},{"name":"\u514d\u8d23\u58f0\u660e","type":"6","target":"\/pages\/common\/clause?type=23"},{"name":"\u6ce8\u9500\u8d26\u53f7","type":"6","target":"\/pagesA\/mine\/logoff\/logoff"}]', true);
        }
        $cosV5 = Settings::get('cosv5', []);
        _update_env([
            "WECHATSERVICEACCOUNT_CLIENT_ID" => Settings::get('mp_app_id'),
            "WECHATSERVICEACCOUNT_CLIENT_SECRET" => Settings::get('mp_app_secret'),

            "WEIXIN_KEY" => Settings::get('app_app_id'),
            "WEIXIN_SECRET" => Settings::get('app_app_secret'),

            "COSV5_APP_ID" => $cosV5['appId'] ?? '',
            "COSV5_SECRET_ID" => $cosV5['secretId'] ?? '',
            "COSV5_SECRET_KEY" => $cosV5['secretKey'] ?? '',
            "COSV5_BUCKET" => $cosV5['bucket'] ?? '',
            "COSV5_REGION" => $cosV5['region'] ?? '',
            "COSV5_CDN" => str_replace(['https://', 'http://'], '', $cosV5['domain'] ?? ''),

        ], ['COSV5_TOKEN', 'COSV5_TIMEOUT', 'COSV5_CONNECT_TIMEOUT', 'COSV5_SCHEME', 'COSV5_READ_FROM_CDN', 'COSV5_CDN_KEY', 'COSV5_ENCRYPT']);
    }

    function _v1_1_0_3()
    {
        if(!Schema::hasColumn('wx_posts', 'ip')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('district')->nullable()->after('device')->comment('县城');
                $table->string('city')->nullable()->after('device')->comment('城市');
                $table->string('province')->nullable()->after('device')->comment('省份');
                $table->string('country')->nullable()->after('device')->comment('国家');
                $table->double('latitude', 10, 6)->nullable()->after('device')->comment('纬度');
                $table->double('longitude', 10, 6)->nullable()->after('device')->comment('经度');
                $table->string('ip')->nullable()->after('device')->comment('ip地址');
            });
        }

        if(!Schema::hasColumn('wx_comment', 'ip')){
            Schema::table('wx_comment', function (Blueprint $table) {
                $table->string('district')->nullable()->after('device')->comment('县城');
                $table->string('city')->nullable()->after('device')->comment('城市');
                $table->string('province')->nullable()->after('device')->comment('省份');
                $table->string('country')->nullable()->after('device')->comment('国家');
                $table->double('latitude', 10, 6)->nullable()->after('device')->comment('纬度');
                $table->double('longitude', 10, 6)->nullable()->after('device')->comment('经度');
                $table->string('ip')->nullable()->after('device')->comment('ip地址');
            });
        }

        if(!Schema::hasColumn('wx_user', 'ip')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->double('latitude', 10, 6)->nullable()->after('city')->comment('纬度');
                $table->double('longitude', 10, 6)->nullable()->after('city')->comment('经度');
                $table->string('ip')->nullable()->after('city')->comment('ip地址');
                $table->string('district')->nullable()->after('city')->comment('县城');
            });
        }


        if(!Schema::hasColumn('wx_tags', 'ip')){
            Schema::table('wx_tags', function (Blueprint $table) {
                $table->string('district')->nullable()->after('tags_number')->comment('县城');
                $table->string('city')->nullable()->after('tags_number')->comment('城市');
                $table->string('province')->nullable()->after('tags_number')->comment('省份');
                $table->string('country')->nullable()->after('tags_number')->comment('国家');
                $table->double('latitude', 10, 6)->nullable()->after('tags_number')->comment('纬度');
                $table->double('longitude', 10, 6)->nullable()->after('tags_number')->comment('经度');
                $table->string('ip')->nullable()->after('tags_number')->comment('ip地址');
            });
        }


        if(!Schema::hasColumn('wx_shop_goods', 'ip')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->string('district')->nullable()->after('service_id')->comment('县城');
                $table->string('city')->nullable()->after('service_id')->comment('城市');
                $table->string('province')->nullable()->after('service_id')->comment('省份');
                $table->string('country')->nullable()->after('service_id')->comment('国家');
                $table->double('latitude', 10, 6)->nullable()->after('service_id')->comment('纬度');
                $table->double('longitude', 10, 6)->nullable()->after('service_id')->comment('经度');
                $table->string('ip')->nullable()->after('service_id')->comment('ip地址');
            });
        }


        if(!Schema::hasColumn('wx_search', 'ip')){
            Schema::table('wx_search', function (Blueprint $table) {
                $table->string('district')->nullable()->after('search_content')->comment('县城');
                $table->string('city')->nullable()->after('search_content')->comment('城市');
                $table->string('province')->nullable()->after('search_content')->comment('省份');
                $table->string('country')->nullable()->after('search_content')->comment('国家');
                $table->double('latitude', 10, 6)->nullable()->after('search_content')->comment('纬度');
                $table->double('longitude', 10, 6)->nullable()->after('search_content')->comment('经度');
                $table->string('ip')->nullable()->after('search_content')->comment('ip地址');
            });
        }

        if(Schema::hasTable('wx_files')){
            Schema::rename('wx_files', 'wx_posts_files');
        }

        if(Schema::hasTable('wx_sounds')){
            Schema::rename('wx_sounds', 'wx_posts_sounds');
        }

        if(Schema::hasTable('wx_post_meta_num')){
            Schema::rename('wx_post_meta_num', 'wx_posts_meta_num');
        }

        if(Schema::hasTable('wx_post_meta_str')){
            Schema::rename('wx_post_meta_str', 'wx_posts_meta_str');
        }

        if(!Schema::hasColumn('wx_posts', 'post_type')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('post_type')->default('words')->nullable()->after('circle_name')->comment('文章类型');
            });
        }

        if(!Schema::hasColumn('wx_circle', 'list_style')){
            Schema::table('wx_circle', function (Blueprint $table) {
                $table->tinyInteger('list_style')->default(0)->after('sort')->comment('展示样式');
            });
        }

        if(!Schema::hasColumn('wx_notice', 'icon_type')){
            Schema::table('wx_notice', function (Blueprint $table) {
                $table->integer('icon_type')->default(0)->after('notice_type')->comment('图标类型');
            });
        }

    }


    function _v1_1_0_8()
    {
        if(!Schema::hasColumn('wx_user_withdrawal', 'pay_amount')){
            Schema::table('wx_user_withdrawal', function (Blueprint $table) {
                $table->float('pay_amount')->nullable()->after('price')->comment('应打款金额');
            });
        }

        if(Menu::where( [ ['title','=', '分销系统'], ['icon', '=', 'fa-fort-awesome'] ] )->exists()){
            Menu::where( [ ['title','=', '分销系统'], ['icon', '=', 'fa-fort-awesome'] ] )->update(['title'=>'分享裂变']);
        }

        if(!Menu::where('uri', '/posts/paycontent')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 14;
            $admin_menu->order =  30;
            $admin_menu->title = '付费';
            $admin_menu->uri = '/posts/paycontent';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    function _v1_1_0_12()
    {
        if (! Schema::hasTable('admin_operation_log')) {
            Schema::create('admin_operation_log', function (Blueprint $table) {
                $table->bigIncrements('id')->unsigned();
                $table->bigInteger('user_id')->comment('管理员id');
                $table->string('path')->comment('请求路径');
                $table->string('method', 10)->comment('请求类型');
                $table->string('ip')->comment('请求ip');
                $table->text('input')->comment('请求参数');
                $table->index('user_id','index_0');
                $table->timestamps();
            });
        }

        if( !Menu::where('uri', 'auth/operation-logs')->exists() ) {
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-spin fa-circle-o-notch';
            $admin_menu->parent_id = 0;
            $admin_menu->order = 9999999999;
            $admin_menu->title = '操作日志';
            $admin_menu->extension = '';
            $admin_menu->uri = 'auth/operation-logs';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_admin_operation_log_parent_id', $parent_id);
        }

    }

    function _v1_1_0_14()
    {
        if(!Menu::where('uri', '/settings/post')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  19;
            $admin_menu->title = '笔记';
            $admin_menu->uri = '/settings/post';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
    }


    function _v1_1_1_10()
    {
        // ios用户登录 openid
        if(!Schema::hasColumn('wx_user', 'apple_openid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('apple_openid', 255)->nullable()->after('user_mobile')->comment('ios用户openid');
                $table->unique('apple_openid', 'index_21');
            });
        }
    }

    function _v1_1_1_11()
    {
        if(!Schema::hasColumn('wx_attachment', 'type')){
            Schema::table('wx_attachment', function (Blueprint $table) {
                $table->string('type', 20)->nullable()->after('path')->comment('附件类型');
            });
        }
    }

    function _v1_1_1_12()
    {
        if(_empty_(Settings::get('app_login_style', []))){
            Settings::set('app_login_style', json_encode([0]), true);
        }
        if(_empty_(Settings::get('app_register_style', []))){
            Settings::set('app_register_style', json_encode([0]), true);
        }
    }


    function _v1_1_1_14()
    {
        if(!Schema::hasColumn('wx_user_temp', 'gender')){
            Schema::table('wx_user_temp', function (Blueprint $table) {
                $table->tinyInteger('gender')->nullable()->after('user_mobile')->comment('性别（0：未知，1：男，2：女）');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'refer_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->bigInteger('refer_id')->nullable()->after('pay_content_id')->index('index_3')->comment('转发ID');
            });
        }

    }

    function _v1_1_1_15()
    {
        if(!Schema::hasColumn('wx_chat', 'refer_id')){
            Schema::table('wx_chat', function (Blueprint $table) {
                $table->bigInteger('refer_id')->nullable()->after('chat_audio_length')->comment('转发id');
            });
        }

        if(!Schema::hasColumn('wx_notice', 'url')){
            Schema::table('wx_notice', function (Blueprint $table) {
                $table->string('url', 255)->nullable()->after('icon_type')->comment('pc端场景等使用');
            });
        }

    }

    function _v1_1_1_19()
    {
        if(Settings::get('img_style_action', -1) < 0){
            if(_empty_(Settings::get('img_style', []))){
                Settings::set('img_style_action', 1);
            }else{
                Settings::set('img_style_action', 2);
            }
        }
    }

    function _v1_1_2_2()
    {
        if(!Schema::hasTable('wx_user_financial_freeze')){
            Schema::create('wx_user_financial_freeze', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->index('index_0')->comment('用户id');
                $table->bigInteger('shop_order_id')->nullable()->index('index_1')->comment('购物车订单id');
                $table->bigInteger('order_goods_id')->nullable()->index('index_2')->comment('订单商品id');
                // （0：默认 1：定时解冻）
                $table->unsignedTinyInteger('type')->default(0)->comment('冻结类型');
                $table->decimal('freeze_amout')->comment('冻结金额');
                $table->string('freeze_reason')->nullable()->comment('冻结理由');
                $table->unsignedTinyInteger('freeze_status')->default(0)->comment('状态（0：冻结中 1：已解冻）');
                $table->string('para')->nullable()->comment('参数');
                $table->softDeletes();
                $table->timestamps();
            });
        }
    }

    function _v1_1_2_3()
    {
        if(!Schema::hasTable('wx_str_meta_num')){
            Schema::create('wx_str_meta_num', function (Blueprint $table) {
                $table->id();
                $table->string('meta_name', 255)->comment('meta_name');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['meta_name','meta_key'], 'index_0');
            });
        }
        if(!Schema::hasTable('wx_str_meta_str')){
            Schema::create('wx_str_meta_str', function (Blueprint $table) {
                $table->id();
                $table->string('meta_name', 255)->comment('meta_name');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['meta_name','meta_key'], 'index_0');
            });
        }
    }

    function _v1_1_2_4()
    {
        if(!Schema::hasColumn('wx_user_financial_freeze', 'para')){
            Schema::table('wx_user_financial_freeze', function (Blueprint $table) {
                $table->string('para')->nullable()->after('freeze_status')->comment('参数');
                $table->bigInteger('order_goods_id')->nullable()->after('user_id')->index('index_2')->comment('订单商品id');
                $table->bigInteger('shop_order_id')->nullable()->after('user_id')->index('index_1')->comment('购物车订单id');
            });
        }


        if(!Schema::hasColumn('wx_shop_goods', 'users_ledger')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->string('users_ledger')->nullable()->after('service_id')->comment('分账用户');
            });
        }
    }

    function _v1_1_2_5(){

        if(!Schema::hasTable('admin_sub_menu')) {
            Schema::create('admin_sub_menu', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('parent_id')->default(0);
                $table->integer('order')->default(0);
                $table->string('title', 50);
                $table->string('icon', 50)->nullable();
                $table->string('uri', 50)->nullable();
                $table->string('extension', 50)->default('');
                $table->tinyInteger('show')->default(1);
                $table->timestamps();
            });

            DB::insert("INSERT INTO `admin_sub_menu` VALUES (1, 0, 1, 'Index', 'feather icon-bar-chart-2', '/', '', 1, '2021-01-26 03:40:33', '2023-03-06 17:37:15');");
            DB::insert("INSERT INTO `admin_sub_menu` VALUES (2, 0, 999, '开发配置', 'feather icon-settings', NULL, '', 1, '2021-01-26 03:40:33', '2023-03-06 17:37:15');");
            DB::insert("INSERT INTO `admin_sub_menu` VALUES (3, 2, 46, '团队', NULL, 'auth/users', '', 1, '2021-01-26 03:40:33', '2022-09-19 13:45:56');");
            DB::insert("INSERT INTO `admin_sub_menu` VALUES (4, 2, 47, 'Roles', '', 'auth/roles', '', 1, '2021-01-26 03:40:33', '2022-09-19 13:45:56');");
            DB::insert("INSERT INTO `admin_sub_menu` VALUES (5, 2, 48, 'Permission', '', 'auth/permissions', '', 1, '2021-01-26 03:40:33', '2022-09-19 13:45:56');");
            DB::insert("INSERT INTO `admin_sub_menu` VALUES (6, 2, 49, 'Menu', '', 'auth/menu', '', 1, '2021-01-26 03:40:33', '2022-09-19 13:45:56');");
        }

        if(!AdminSubMenu::where('uri', '/settings/pageindex')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 1;
            $admin_menu->icon = 'fa-home';
            $admin_menu->title = '首页';
            $admin_menu->uri = '/settings/pageindex';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    function _v1_1_3(){

        if(!Schema::hasColumn('wx_circle', 'tenant_id')){
            Schema::table('wx_circle', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('circle_state')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'tenant_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('posts_state')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_plate', 'tenant_id')){
            Schema::table('wx_plate', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('plate_state')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_activity', 'tenant_id')){
            Schema::table('wx_activity', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('status')->comment('tenant_id');
            });
        }


        if(!Schema::hasColumn('wx_user', 'tenant_id')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('user_state')->comment('tenant_id');
            });
        }

        if (_empty_(Settings::get('--color-primary')) || Settings::get('--color-primary') == '#fb7299'){
            Settings::set('--color-primary', '#fc3a72');
        }

    }

    function _v1_1_3_2(){
        if(!Schema::hasTable('wx_posts_field')) {
            Schema::create('wx_posts_field', function (Blueprint $table) {
                $table->unsignedBigInteger('post_id')->primary();
                $table->string('contact_phone', '30')->nullable()->comment('联系手机号');
            });
        }

        if(WxPost::whereNull('circle_id')->exists()){
            WxPost::withoutSyncingToSearch(function (){
                WxPost::whereNull('circle_id')->update(['circle_id'=>0]);
            });
        }
        Schema::table('wx_posts', function (Blueprint $table) {
            $table->unsignedBigInteger('circle_id')->default(0)->change();
        });

        if(!AdminSubMenu::where('uri', '/settings/publish')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 2;
            $admin_menu->icon = 'fa-eraser';
            $admin_menu->title = '编辑器配置';
            $admin_menu->uri = '/settings/publish';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/settings/circle')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 3;
            $admin_menu->icon = 'fa-circle-o-notch';
            $admin_menu->title = '圈子配置';
            $admin_menu->uri = '/settings/circle';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/settings/ad')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 3;
            $admin_menu->icon = 'fa-buysellads';
            $admin_menu->title = '广告配置';
            $admin_menu->uri = '/settings/ad';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/settings/post')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 4;
            $admin_menu->icon = 'fa-newspaper-o';
            $admin_menu->title = '笔记配置';
            $admin_menu->uri = '/settings/post';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }


        if(!AdminSubMenu::where('uri', '/plate')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 5;
            $admin_menu->icon = 'fa-square';
            $admin_menu->title = '板块管理';
            $admin_menu->uri = '/plate';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/circle')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 6;
            $admin_menu->icon = 'fa-dot-circle-o';
            $admin_menu->title = '圈子管理';
            $admin_menu->uri = '/circle';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/posts/index')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 7;
            $admin_menu->icon = 'fa-edit';
            $admin_menu->title = '笔记管理';
            $admin_menu->uri = '/posts/index';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/commen')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 8;
            $admin_menu->icon = 'fa-comments-o';
            $admin_menu->title = '评论管理';
            $admin_menu->uri = '/commen';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    function _v1_1_3_3(){

        if(WxPost::whereNull('circle_id')->exists()){
            WxPost::withoutSyncingToSearch(function (){
                WxPost::whereNull('circle_id')->update(['circle_id'=>0]);
            });
        }

        foreach (['wx_circle','wx_posts','wx_plate','wx_activity','wx_user'] as $table_name){
            $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM '.$table_name));
            foreach($table_info_columns as $column){
                if($column->Field == 'tenant_id'){
                    $col_type = $column->Type;
                    if($col_type == 'tinyint(3) unsigned'){
                        Schema::table($table_name, function (Blueprint $table) {
                            $table->unsignedInteger('tenant_id')->change();
                        });
                    }
                }
            }
        }
    }

    function _v1_1_3_6(){
        global $__MINI_GLOBAL_PAYCODE_25__;

        if($__MINI_GLOBAL_PAYCODE_25__){
            if( !(Settings::get('menu_pets_parent_id', 0, false, false) > 0) && !(Menu::where('title', '宠物系统')->exists()) ){
                $admin_menu = new Menu();
                $admin_menu->icon = 'fa-github-alt';
                $admin_menu->parent_id = 0;
                $admin_menu->order =  50;
                $admin_menu->title = '宠物系统';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
                $parent_id = $admin_menu->id;
                Settings::set('menu_pets_parent_id', $parent_id);

                if(!Menu::where('uri', '/pets/config')->exists()){
                    $admin_menu = new Menu();
                    $admin_menu->parent_id = $parent_id;
                    $admin_menu->order =  0;
                    $admin_menu->title = '配置';
                    $admin_menu->uri = '/pets/config';
                    $admin_menu->extension = '';
                    $admin_menu->show = 1;
                    $admin_menu->save();
                }

//                if(!Menu::where('uri', '/pets/index')->exists()){
//                    $admin_menu = new Menu();
//                    $admin_menu->parent_id = $parent_id;
//                    $admin_menu->order =  1;
//                    $admin_menu->title = '宠物';
//                    $admin_menu->uri = '/pets/index';
//                    $admin_menu->extension = '';
//                    $admin_menu->show = 1;
//                    $admin_menu->save();
//                }

                if(!Menu::where('uri', '/pets/adoption/index')->exists()){
                    $admin_menu = new Menu();
                    $admin_menu->parent_id = $parent_id;
                    $admin_menu->order =  1;
                    $admin_menu->title = '领养';
                    $admin_menu->uri = '/pets/adoption/index';
                    $admin_menu->extension = '';
                    $admin_menu->show = 1;
                    $admin_menu->save();
                }

                if(!Menu::where('uri', '/pets/adoption/apply')->exists()){
                    $admin_menu = new Menu();
                    $admin_menu->parent_id = $parent_id;
                    $admin_menu->order =  2;
                    $admin_menu->title = '申请';
                    $admin_menu->uri = '/pets/adoption/apply';
                    $admin_menu->extension = '';
                    $admin_menu->show = 1;
                    $admin_menu->save();
                }

            }

            if(!Schema::hasTable('wx_pets_adoption')) {

                Schema::create('wx_pets_adoption', function (Blueprint $table) {
                    $table->increments('id');
                    $table->unsignedBigInteger('user_id')->comment('用户id');
                    $table->unsignedBigInteger('success_user_id')->nullable()->comment('申请成功用户id');
                    $table->string('name', 100)->comment('名称');

                    $table->string('pictures', 800)->comment('图片');
                    // 1: 猫咪 2：狗狗
                    $table->unsignedTinyInteger('species')->default(0)->comment('种类');
                    $table->string('pet_breed', 100)->nullable()->comment('品种');

                    // 0:免费     1：有偿    2：收押金
                    $table->unsignedTinyInteger('is_free')->default(0)->comment('领养方式');
                    $table->float('cost')->default(0)->comment('押金');

                    // （0：未知，1：男，2：女 3：雌雄同体）
                    $table->unsignedTinyInteger('pet_gender')->default(0)->comment('性别');
                    $table->dateTime('pet_age')->nullable()->comment('宠物年龄');

                    $table->unsignedTinyInteger('is_vaccine')->default(0)->comment('是否注射疫苗');
                    $table->unsignedTinyInteger('is_sterilization')->default(0)->comment('是否绝育');
                    $table->unsignedTinyInteger('is_repellent')->default(0)->comment('是否驱虫');


                    $table->string('pet_introduce', 600)->nullable()->comment('故事');

                    // 1,2,3
                    $table->string('condition', 50)->nullable()->comment('领养条件');

                    $table->string('province', 50)->nullable()->comment('省份');
                    $table->string('city', 50)->nullable()->comment('市');
                    $table->string('district', 50)->nullable()->comment('县');
                    $table->string('address', 255)->nullable()->comment('详细地址');

                    $table->string('adopter_name', 50)->nullable()->comment('送养人姓名');
                    $table->string('adopter_mobile', 50)->nullable()->comment('送养人手机号');
                    $table->string('adopter_wechatId', 100)->nullable()->comment('送养人微信号');

                    $table->string('adopter_ip', 100)->nullable()->comment('领养人ip地址');

                    // 0: 正常推送  1：已领养 2：废弃 3: 审核中
                    $table->unsignedTinyInteger('adopt_status')->default(0)->comment('状态');

                    $table->timestamps();
                });

            }

            // 领养申请
            if(!Schema::hasTable('wx_pets_adoption_apply')) {
                Schema::create('wx_pets_adoption_apply', function (Blueprint $table) {
                    $table->increments('id');

                    $table->unsignedBigInteger('user_id')->comment('用户id');
                    $table->unsignedBigInteger('pet_adoption_id')->comment('领养id');

                    // （0：未知，1：男，2：女 3：雌雄同体）
                    $table->unsignedTinyInteger('gender')->default(0)->comment('性别');
                    $table->unsignedTinyInteger('is_experience')->default(0)->comment('养宠经验');
                    $table->unsignedTinyInteger('marital_status')->default(0)->comment('婚姻状况');
                    $table->unsignedTinyInteger('housing_status')->default(0)->comment('住房情况');
                    $table->unsignedTinyInteger('working_status')->default(0)->comment('工作状态');

                    $table->string('job', 255)->nullable()->comment('职业');
                    $table->dateTime('birthday')->nullable()->comment('生日');
                    $table->unsignedInteger('income')->default(0)->comment('收入');

                    $table->string('province', 50)->nullable()->comment('省份');
                    $table->string('city', 50)->nullable()->comment('市');
                    $table->string('district', 50)->nullable()->comment('县');

                    $table->string('mobile', 50)->nullable()->comment('手机号');
                    $table->string('wechatId', 100)->nullable()->comment('微信号');

                    $table->string('remark', 600)->nullable()->comment('简介');

                    // 0: 申请中 1：申请成功 2：被拒绝
                    $table->unsignedInteger('status')->default(0)->comment('申请状态');

                    $table->timestamps();
                });
            }

            if(!Schema::hasTable('wx_pets_adoption_collect')) {
                Schema::create('wx_pets_adoption_collect', function (Blueprint $table) {
                    $table->increments('id');
                    $table->unsignedBigInteger('user_id')->comment('用户id');
                    $table->unsignedBigInteger('pet_adoption_id')->comment('领养id');
                    $table->timestamps();
                });
            }

        }
    }

    function _v1_1_3_9(){
        if( !(Settings::get('menu_luck_draw_parent_id', 0, false, false) > 0) && !(Menu::where('title', '抽奖系统')->exists()) ){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-delicious';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  51;
            $admin_menu->title = '抽奖系统';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_luck_draw_parent_id', $parent_id);

            if(!Menu::where('uri', '/luckdraw/config')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  0;
                $admin_menu->title = '转盘';
                $admin_menu->uri = '/luckdraw/config';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/luckdraw/record')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  1;
                $admin_menu->title = '记录';
                $admin_menu->uri = '/luckdraw/record';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }
        }

        if(Menu::where('uri', '/user/luckdraw')->exists()){
            Menu::where('uri', '/user/luckdraw')->delete();
        }

        if(!Schema::hasColumn('wx_posts_vote', 'option6')){
            Schema::table('wx_posts_vote', function (Blueprint $table) {
                $table->string('option6')->nullable()->comment('选项6');
                $table->bigInteger('num6')->default(0)->comment('选项6投票数');

                $table->string('option7')->nullable()->comment('选项7');
                $table->bigInteger('num7')->default(0)->comment('选项7投票数');

                $table->string('option8')->nullable()->comment('选项8');
                $table->bigInteger('num8')->default(0)->comment('选项8投票数');

                $table->string('option9')->nullable()->comment('选项9');
                $table->bigInteger('num9')->default(0)->comment('选项9投票数');

                $table->string('option10')->nullable()->comment('选项10');
                $table->bigInteger('num10')->default(0)->comment('选项10投票数');

                $table->string('option11')->nullable()->comment('选项11');
                $table->bigInteger('num11')->default(0)->comment('选项11投票数');

                $table->string('option12')->nullable()->comment('选项12');
                $table->bigInteger('num12')->default(0)->comment('选项12投票数');

                $table->string('option13')->nullable()->comment('选项13');
                $table->bigInteger('num13')->default(0)->comment('选项13投票数');

                $table->string('option14')->nullable()->comment('选项14');
                $table->bigInteger('num14')->default(0)->comment('选项14投票数');

                $table->string('option15')->nullable()->comment('选项15');
                $table->bigInteger('num15')->default(0)->comment('选项15投票数');

                $table->string('option16')->nullable()->comment('选项16');
                $table->bigInteger('num16')->default(0)->comment('选项16投票数');

                $table->string('option17')->nullable()->comment('选项17');
                $table->bigInteger('num17')->default(0)->comment('选项17投票数');

                $table->string('option18')->nullable()->comment('选项18');
                $table->bigInteger('num18')->default(0)->comment('选项18投票数');

                $table->string('option19')->nullable()->comment('选项19');
                $table->bigInteger('num19')->default(0)->comment('选项19投票数');

                $table->string('option20')->nullable()->comment('选项20');
                $table->bigInteger('num20')->default(0)->comment('选项20投票数');
            });
        }

    }

    function _v1_1_3_10(){
        if(!Schema::hasColumn('wx_shop_order', 'pay_way')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->string('pay_way')->nullable()->after('coins_pay')->comment('支付途径');
            });
        }
    }

    function _v1_1_3_11(){
        if(env('APP_URL', '') == 'https://mini.minisns.cn'){
            if(!Menu::where('uri', '/mini/admin/menu_search')->exists()){
                $admin_menu = new Menu();
                $admin_menu->icon = 'fa-modx';
                $admin_menu->parent_id = 0;
                $admin_menu->order =  52;
                $admin_menu->title = '后台搜索';
                $admin_menu->uri = '/mini/admin/menu_search';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }
            if(!Menu::where('uri', '/mini/admin/domain_auth')->exists()){
                $admin_menu = new Menu();
                $admin_menu->icon = 'fa fa-creative-commons';
                $admin_menu->parent_id = 0;
                $admin_menu->order =  53;
                $admin_menu->title = '域名授权';
                $admin_menu->uri = '/mini/admin/domain_auth';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }
        }
    }

    function _v1_1_3_12(){
        if(!Schema::hasColumn('wx_posts', 'is_wechat_sph')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->boolean('is_wechat_sph')->default(false)->after('img_count')->comment('视频号内容');
            });
        }
    }

    function _v1_1_4(){

        if(!AdminSubMenu::where('uri', '/users')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 9;
            $admin_menu->icon = 'fa-fw fa-group';
            $admin_menu->title = '用户管理';
            $admin_menu->uri = '/users';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/settings/safe')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 10;
            $admin_menu->icon = 'fa-warning';
            $admin_menu->title = '安全配置';
            $admin_menu->uri = '/settings/safe';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }


        if(!Schema::hasColumn('wx_slideshow', 'tenant_id')){
            Schema::table('wx_slideshow', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('slideshow_state')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_tasks', 'tenant_id')){
            Schema::table('wx_tasks', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('target_id')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_icons', 'tenant_id')){
            Schema::table('wx_icons', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('target_id')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_questions', 'tenant_id')){
            Schema::table('wx_questions', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('type')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_search', 'tenant_id')){
            Schema::table('wx_search', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('is_hot')->comment('tenant_id');
            });
        }

        if(!Schema::hasColumn('wx_user_avatar_frame', 'tenant_id')){
            Schema::table('wx_user_avatar_frame', function (Blueprint $table) {
                $table->unsignedInteger('tenant_id')->default(0)->after('status')->comment('tenant_id');
            });
        }

        if( !(Settings::get('sub_menu_ku_parent_id', 0, false, false) > 0) && !(AdminSubMenu::where('title', '库')->exists()) ){
            $admin_menu = new AdminSubMenu();
            $admin_menu->icon = 'fa-archive';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  11;
            $admin_menu->title = '库';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('sub_menu_ku_parent_id', $parent_id);

            if(!AdminSubMenu::where('uri', '/slideshow')->exists()){
                $admin_menu = new AdminSubMenu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  0;
                $admin_menu->title = '轮播图库';
                $admin_menu->uri = '/slideshow';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!AdminSubMenu::where('uri', '/settings/icons')->exists()){
                $admin_menu = new AdminSubMenu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  1;
                $admin_menu->title = '图标库';
                $admin_menu->uri = '/settings/icons';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!AdminSubMenu::where('uri', '/qa/question')->exists()){
                $admin_menu = new AdminSubMenu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  2;
                $admin_menu->title = '帮助问答库';
                $admin_menu->uri = '/qa/question';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }


        if (! Schema::hasTable('wx_tenants')) {
            Schema::create('wx_tenants', function (Blueprint $table) {
                $table->unsignedBigInteger('tenant_id')->comment('分站id')->unique()->primary();
                $table->unsignedBigInteger('order')->default(0)->comment('排序');
                $table->string('name')->comment('名称')->unique('index_0');
                $table->string('short')->nullable()->comment('简称');
                $table->string('logo')->nullable()->comment('Logo');
                $table->string('desc')->nullable()->comment('描述');
                $table->unsignedTinyInteger('is_hot')->default(0)->comment('热门');
                $table->unsignedTinyInteger('status')->default(0)->comment('状态');
                $table->string('tip')->nullable()->comment('备注');
                $table->timestamps();
            });
            DB::insert("INSERT INTO `wx_tenants` VALUES (0, 9999, '主站', '主站', '', '', 0, 0, '', '2021-01-26 03:40:33', '2023-03-06 17:37:15');");
            DB::insert("INSERT INTO `wx_tenants` VALUES (999, 0, '多应用免费测试', '测试', '', '用于测试分应用', 0, 0, '', '2021-01-26 03:40:34', '2023-03-06 17:37:16');");
        }

    }


    function _v1_1_4_2(){
        if(!Schema::hasColumn('wx_shop_order', 'adds_id')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->unsignedBigInteger('adds_id')->nullable()->after('cost_freight')->comment('地址id');
            });
        }
    }

    function _v1_1_4_3(){
        if(!Schema::hasColumn('wx_tenants', 'order')){
            Schema::table('wx_tenants', function (Blueprint $table) {
                $table->unsignedBigInteger('order')->default(0)->after('tenant_id')->comment('排序');
            });
        }
        if(!Schema::hasColumn('wx_tenants', 'is_hot')){
            Schema::table('wx_tenants', function (Blueprint $table) {
                $table->unsignedTinyInteger('is_hot')->default(0)->after('desc')->comment('热门');
            });
        }
    }

    function _v1_1_4_8(){
        if(!Schema::hasColumn('wx_user_withdrawal', 'real_name')){
            Schema::table('wx_user_withdrawal', function (Blueprint $table) {
                $table->string('alipay_phone')->nullable()->after('bank_card')->comment('支付宝手机号');
                $table->string('wechat_phone')->nullable()->after('bank_card')->comment('微信手机号');
                $table->string('real_name')->nullable()->after('bank_card')->comment('真实名字');
            });
        }
    }

    function _v1_1_4_9(){

        global $__MINI_GLOBAL_TENANT_ID__;
        if($__MINI_GLOBAL_TENANT_ID__ == 0){
            if(!Permission::where('http_path', 'shop/add_goods*')->exists()){
                $perssion = new Permission();
                $perssion->name = '商城管理-新增商品';
                $perssion->slug =  'shop_add_goods';
                $perssion->http_method = null;
                $perssion->http_path = 'shop/add_goods*';
                $perssion->order = 45;
                $perssion->parent_id = 0;
                $perssion->save();
            }
            if(!Permission::where('http_path', 'shop/save_goods*')->exists()){
                $perssion = new Permission();
                $perssion->name = '商城管理-修改商品';
                $perssion->slug =  'shop_save_goods';
                $perssion->http_method = null;
                $perssion->http_path = 'shop/save_goods*';
                $perssion->order = 46;
                $perssion->parent_id = 0;
                $perssion->save();
            }
        }

        if(!Permission::where('http_path', 'files/uploads*,files/ueditor/uploads*')->exists()){
            $perssion = new Permission();
            $perssion->name = '上传图片/附件';
            $perssion->slug =  'files_uploads,files_ueditor_uploads';
            $perssion->http_method = null;
            $perssion->http_path = 'files/uploads*,files/ueditor/uploads*';
            $perssion->order = 47;
            $perssion->parent_id = 0;
            $perssion->save();
        }
    }

    function _v1_1_5(){
        if(!Schema::hasColumn('wx_chat', 'adoption_apply_id')){
            Schema::table('wx_chat', function (Blueprint $table) {
                $table->unsignedBigInteger('adoption_apply_id')->nullable()->after('refer_id')->comment('领养申请id');
            });
        }
    }

    function _v1_1_5_1(){
        if(!Schema::hasColumn('wx_user', 'qq_unionid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('qq_web_openid', 255)->nullable()->after('weixin_shop_openid')->comment('QQ网页应用openid');
                $table->string('qq_app_openid', 255)->nullable()->after('weixin_shop_openid')->comment('QQ移动应用openid');
                $table->string('qq_unionid', 255)->nullable()->after('weixin_shop_openid')->comment('QQunionid');
            });
        }


        if(!Schema::hasColumn('wx_user', 'push_client_id')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('push_client_id', 255)->nullable()->after('user_state')->comment('cid');
            });
        }

    }

    function _v1_1_5_8(){
        if(!Schema::hasColumn('wx_circle', 'square_list')){
            Schema::table('wx_circle', function (Blueprint $table) {
                $table->string('square_list')->nullable()->after('background_maps')->comment('小方格');
            });
        }
    }

    function _v1_1_6_5(){
        if(!Schema::hasColumn('wx_user_circle', 'payment_duration')){
            Schema::table('wx_user_circle', function (Blueprint $table) {
                $table->timestamp('payment_duration')->nullable()->after('user_circle_state')->comment('付费持续时间');
            });
        }

        if(!Schema::hasColumn('wx_comment', 'posts_circle_id')){
            Schema::table('wx_comment', function (Blueprint $table) {
                $table->bigInteger('posts_circle_id')->nullable()->after('posts_user_id')->comment('笔记圈子id');
            });
        }
    }

    function _v1_1_6_6(){
        if (! Schema::hasTable('wx_domain_auth')) {
            Schema::create('wx_domain_auth', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->nullable()->comment('用户id');

                $table->string('domain_1')->comment('域名1');
                $table->string('tenant_1')->nullable()->comment('分站1');

                $table->string('domain_2')->nullable()->comment('域名2');
                $table->string('tenant_2')->nullable()->comment('分站2');

                $table->string('domain_3')->nullable()->comment('域名3');
                $table->string('tenant_3')->nullable()->comment('分站3');

                $table->string('domain_4')->nullable()->comment('域名4');
                $table->string('tenant_4')->nullable()->comment('分站4');

                $table->string('domain_5')->nullable()->comment('域名5');
                $table->string('tenant_5')->nullable()->comment('分站5');

                $table->string('domain_6')->nullable()->comment('域名6');
                $table->string('tenant_6')->nullable()->comment('分站6');

                $table->string('domain_7')->nullable()->comment('域名7');
                $table->string('tenant_7')->nullable()->comment('分站7');

                $table->string('pays')->comment('付费模块');
                $table->string('who')->nullable()->comment('代理人');

                $table->timestamps();
            });
        }
    }

    function _v1_1_6_7(){
        if(!Schema::hasColumn('wx_shop_goods', 'scanners')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->string('scanners')->nullable()->after('sku')->comment('核销员');
            });
        }
    }

    function _v1_1_6_8(){

    }


    function _v1_1_6_9(){

        // 将wx_circle_tag的普通索引改成唯一索引
        try{
            if(Schema::hasTable('wx_circle_tag')){
                $indexes = Schema::getConnection()
                    ->getDoctrineSchemaManager()
                    ->listTableIndexes('wx_circle_tag');
                if($indexes){
                    $indexes = array_keys($indexes);
                    if(in_array('index_0', $indexes)){
                        Schema::table('wx_circle_tag', function (Blueprint $table){
                            // 删除原有索引
                            $table->dropIndex('index_0');
                            // 添加唯一索引
                            $table->unique(['circle_id', 'tag_id'], 'index_1');
                        });
                    }
                }
            }
        }catch (\Exception $e){
            exit('请联系群主微信：ShaoWenSir');
        }

    }


    function _v1_1_6_11(){
        if(!Schema::hasTable('mini_collecter_collected')) {
            Schema::create('mini_collecter_collected', function (Blueprint $table) {
                $table->id();
                $table->string('post_unique', 255);
                $table->string('author_unique', 255);
                $table->string('link')->comment('链接');
                $table->string('author')->comment('昵称');
                $table->string('title', 255)->comment('标题');
                $table->longText('content')->comment('内容');
                $table->longText('imgs')->comment('图片[]');
                $table->longText('comments')->comment('评论[]');
                $table->text('tags')->comment('话题[]');
                $table->text('musics')->comment('音乐[]');
                $table->text('videos')->comment('视频[]');
                $table->unsignedBigInteger('circle_id')->default(0)->comment('圈子id');
                $table->unsignedBigInteger('user_id')->nullable()->comment('强制用户id');
                $table->unsignedBigInteger('tenant_id')->default(0)->comment('分站id');
                $table->unsignedBigInteger('post_id')->default(0)->comment('发布id');
                $table->tinyInteger('status')->default(0)->comment('状态');
                $table->softDeletes();
                $table->timestamps();
                $table->index('post_unique', 'index_0');
                $table->index('author_unique', 'index_1');
                $table->index('post_id', 'index_2');
                $table->index('status', 'index_3');
            });
        }

        if(!Schema::hasTable('mini_collecter_user_map')) {
            Schema::create('mini_collecter_user_map', function (Blueprint $table) {
                $table->string('user_unique')->comment('唯一值')->unique()->primary();
                $table->unsignedBigInteger('user_id')->unique('index_0')->comment('用户id');

            });
        }

        if(Schema::hasTable('mini_collecter_collected') && !Schema::hasColumn('mini_collecter_collected', 'user_id')){
            Schema::table('mini_collecter_collected', function (Blueprint $table) {
                $table->unsignedBigInteger('user_id')->nullable()->after('circle_id')->comment('强制用户id');
            });
        }

        if(Schema::hasTable('mini_collecter_collected') && !Schema::hasColumn('mini_collecter_collected', 'tenant_id')){
            Schema::table('mini_collecter_collected', function (Blueprint $table) {
                $table->unsignedBigInteger('tenant_id')->default(0)->after('circle_id')->comment('分站id');
            });
        }


        if( !(Settings::get('menu_collecter_parent_id', 0, false, false) > 0) && !(Menu::where('title', '收集系统')->exists()) ){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-anchor';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  52;
            $admin_menu->title = '收集系统';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_collecter_parent_id', $parent_id);

            if(!Menu::where('uri', '/collecter/collected')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  0;
                $admin_menu->title = '数据';
                $admin_menu->uri = '/collecter/collected';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }

        if(Settings::get('menu_collecter_parent_id', 0) > 0){
            if(!Menu::where('uri', '/collecter/user_map')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = Settings::get('menu_collecter_parent_id', 0);
                $admin_menu->order =  1;
                $admin_menu->title = '一对一绑定';
                $admin_menu->uri = '/collecter/user_map';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }
        }
    }

    function _v1_1_6_14(){
        if(!Menu::where('uri', '/chats')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 22;
            $admin_menu->order =  10;
            $admin_menu->title = '私信';
            $admin_menu->uri = '/chats';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
    }


    function _v1_1_7_2(){
        if(!Schema::hasColumn('wx_shop_classify', 'depth')){
            Schema::table('wx_shop_classify', function (Blueprint $table) {
                $table->unsignedTinyInteger('depth')->default(1)->after('parent_id')->comment('层级');
            });
        }

    }

    function _v1_1_7_4(){
        if(!Schema::hasTable('wx_user_setting')) {
            Schema::create('wx_user_setting', function (Blueprint $table) {
                $table->unsignedBigInteger('user_id')->unique()->primary()->comment('用户id');
                // 1: 关注我的人 2：我关注的人  3：互相关注的人 4：禁止私信
                $table->unsignedTinyInteger('privacy_message_me')->default(1)->comment('谁可以私信我');
                // 1: 公开 2：私密
                $table->unsignedTinyInteger('privacy_collected_post_show')->default(1)->comment('我的收藏');
                // 1: 公开 2：私密
                $table->unsignedTinyInteger('privacy_my_follow_show')->default(1)->comment('隐藏我的关注列表');
                // 1: 公开 2：私密
                $table->unsignedTinyInteger('privacy_follow_me_show')->default(1)->comment('隐藏我的粉丝列表');

                // 1: 关注我的人 2：我关注的人  3：互相关注的人 4：禁止获取 5：向我付费
                $table->unsignedTinyInteger('privacy_get_my_wechat')->default(4)->comment('允许别人获取我的微信');
                $table->decimal('privacy_get_my_wechat_pay', 8, 2, true)->default(0)->comment('微信号付费数额');

                // 1: 关注我的人 2：我关注的人  3：互相关注的人 4：禁止获取 5：向我付费
                $table->unsignedTinyInteger('privacy_get_my_phone')->default(4)->comment('允许别人获取我的手机号');
                $table->decimal('privacy_get_my_phone_pay', 8, 2, true)->default(0)->comment('手机号付费数额');

                // 1: 推荐 2：不推荐
                $table->unsignedTinyInteger('privacy_personal_recommend_user')->default(1)->comment('不给我推荐可能认识的人');
                // 1: 开启 2：关闭
                $table->unsignedTinyInteger('privacy_personal_recommend')->default(1)->comment('个性化推荐');
                // 1: 开启 2：关闭
                $table->unsignedTinyInteger('privacy_personal_ad')->default(1)->comment('程序化广告配置');
                // 1: 开启 2：关闭
                $table->unsignedTinyInteger('privacy_personal_geo_title')->default(1)->comment('允许地理标题推荐');
                // 1: 默认 2：列表式 3：瀑布流
                $table->unsignedTinyInteger('diy_scene_1_post_list_style')->default(1)->comment('首页瀑布流');
                // 1: 默认 2：列表式 3：瀑布流
                $table->unsignedTinyInteger('diy_scene_6_post_list_style')->default(1)->comment('圈子瀑布流');
                // 1: 默认 2：列表式 3：瀑布流
                $table->unsignedTinyInteger('diy_scene_7_post_list_style')->default(1)->comment('话题瀑布流');
                // 1: 默认 2：列表式 3：瀑布流
                $table->unsignedTinyInteger('diy_scene_8_post_list_style')->default(1)->comment('用户瀑布流');
            });
        }

        if(!WxUserSetting::exists()){
            foreach (WxUser::pluck('id') as $user_id){
                try {
                    $model = new WxUserSetting();
                    $model->user_id = $user_id;
                    $model->save();
                }catch (\Exception $e){

                }
            }
        }

    }

    function _v1_1_7_5(){

        $flag = false;
        if(!Schema::hasTable('wx_shop')) {
            $flag = true;
        }else if(Schema::hasTable('wx_shop') && !Schema::hasColumn('wx_shop', 'admin_user_id')){
            Schema::dropIfExists('wx_shop');
            $flag = true;
        }

        if($flag){
            Schema::create('wx_shop', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->unique('index_0')->comment('用户id');
                $table->unsignedBigInteger('admin_user_id')->nullable()->index('index_2')->comment('后台用户id');
                // 店铺信息
                $table->string('shop_logo')->nullable()->comment('店铺logo');
                $table->string('shop_name')->index('index_1')->comment('店铺名');
                $table->string('shop_background_map')->nullable()->comment('店铺横幅');
                $table->string('shop_introduce')->nullable()->comment('店铺介绍');
                // 1：个人店 2：个体户 3：企业店 4：旗舰店
                $table->unsignedTinyInteger('shop_type')->default(1)->comment('店铺类型');
                // 信用最多100分，扣完自动下线
                $table->float('shop_credit_score')->default(5)->comment('店铺信用');

                // 企业微信客服系统-企业ID
                $table->string('shop_corpid')->nullable()->comment('企业微信-企业号');
                $table->string('shop_service_url')->nullable()->comment('企业微信-客服链接');
                $table->string('shop_classifys')->nullable()->comment('店铺类目');

                // 保证金（保证金处冻结状态）// todo: 此处差一个保证金记录
                $table->float('margin_rest')->default(0)->comment('剩余保证金');
                $table->float('margin_least')->default(0)->comment('最少应缴保证金');
                // 公司信息
                $table->string('business_license_image')->nullable()->comment('公司营业执照');
                $table->string('business_name')->nullable()->comment('公司名称');
                $table->string('business_social_credit_code')->nullable()->comment('公司统一社会信用代码');
                $table->timestamp('business_deadline')->nullable()->comment('公司执照过期时间');
                $table->string('business_trademark_1')->nullable()->comment('公司商标1');
                $table->string('business_trademark_2')->nullable()->comment('公司商标2');

                // 负责人信息
                $table->string('head_addr_country')->nullable()->comment('负责人国家');
                $table->string('head_addr_province')->nullable()->comment('负责人省份');
                $table->string('head_addr_city')->nullable()->comment('负责人城市');
                $table->string('head_addr_district')->nullable()->comment('负责人县城');
                $table->string('head_addr_detail')->nullable()->comment('负责人详细地址');

                $table->string('head_phone')->nullable()->comment('负责人电话');
                $table->string('head_wechat')->nullable()->comment('负责人微信');
                $table->string('head_qq')->nullable()->comment('负责人QQ');
                $table->string('head_name')->nullable()->comment('负责人名字');
                $table->string('head_photo')->nullable()->comment('负责人照片');
                $table->string('head_id_card_a')->nullable()->comment('负责人身份证A');
                $table->string('head_id_card_b')->nullable()->comment('负责人身份证B');
                $table->string('head_id_card_num')->nullable()->comment('身份证号码');
                $table->string('head_id_card_addr')->nullable()->comment('身份证地址');

                $table->string('consignee_name')->nullable()->comment('默认退货人-姓名');

                $table->string('consignee_addr_country')->nullable()->comment('默认退货人-国家');
                $table->string('consignee_addr_province')->nullable()->comment('默认退货人-省份');
                $table->string('consignee_addr_city')->nullable()->comment('默认退货人-城市');
                $table->string('consignee_addr_district')->nullable()->comment('默认退货人-县城');
                $table->string('consignee_addr_detail')->nullable()->comment('默认退货人-详细');
                $table->string('consignee_phone')->nullable()->comment('默认退货人-电话');

                $table->string('supplement')->nullable()->comment('补充');
                // [0=>'审核中', 1=>'审核通过',2=>'审核拒绝', 3=> '系统惩罚下线', 4 => '管理员惩罚下线', 5=> '店主关停']
                $table->unsignedTinyInteger('status')->default(0)->comment('店铺状态');
                $table->string('refuse_reason')->nullable()->comment('拒绝理由');
                $table->softDeletes();
                $table->timestamps();
            });
        }


        if(!Schema::hasColumn('wx_user', 'shop_id')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->unsignedBigInteger('shop_id')->nullable()->after('user_state')->unique()->comment('店铺id');
            });
        }

        if(!Menu::where('uri', '/shops')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 36;
            $admin_menu->order =  11;
            $admin_menu->title = '店铺';
            $admin_menu->uri = '/shops';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasColumn('wx_shop_goods', 'shop_id')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->unsignedBigInteger('shop_id')->default(0)->after('id')->index('index_4')->comment('店铺id');
            });
        }

        if(!Schema::hasColumn('wx_shop_goods', 'user_id')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->unsignedBigInteger('user_id')->default(0)->after('id')->index('index_6')->comment('卖家id');
            });
        }

        if(!Schema::hasTable('wx_shop_meta_num')){
            Schema::create('wx_shop_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('shop_id')->comment('shop_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['user_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_shop_meta_str')){
            Schema::create('wx_shop_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('shop_id')->comment('shop_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['user_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasColumn('wx_shop_goods', 'url_word')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->string('url_word')->nullable()->after('url')->comment('口令');
            });
        }

        if(!Menu::where('uri', '/settings/shop')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 60;
            $admin_menu->order =  20;
            $admin_menu->title = '商城';
            $admin_menu->uri = '/settings/shop';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    function _v1_1_7_6(){
        if(!Schema::hasColumn('wx_shop_classify', 'guarantee')){
            Schema::table('wx_shop_classify', function (Blueprint $table) {
                // 1允许 0：不允许
                $table->unsignedTinyInteger('is_shop_type4')->default(1)->after('bg_img')->comment('旗舰店/专卖店可卖');
                $table->unsignedTinyInteger('is_shop_type3')->default(1)->after('bg_img')->comment('企业店可卖');
                $table->unsignedTinyInteger('is_shop_type2')->default(1)->after('bg_img')->comment('个体户可卖');
                $table->unsignedTinyInteger('is_shop_type1')->default(1)->after('bg_img')->comment('个人店可卖');
                $table->float('guarantee')->nullable()->after('bg_img')->comment('保证金');
            });
        }

        if(!Schema::hasColumn('wx_tenants', 'add_latitude')){
            Schema::table('wx_tenants', function (Blueprint $table) {
                $table->double('add_latitude', 10, 6)->nullable()->after('desc')->comment('纬度');
                $table->double('add_longitude', 10, 6)->nullable()->after('desc')->comment('经度');
                // 1允许 0：不允许
                $table->string('add_detail')->nullable()->after('desc')->comment('详细');
                $table->string('add_district')->nullable()->after('desc')->comment('县');
                $table->string('add_city')->nullable()->after('desc')->comment('市');
                $table->string('add_province')->nullable()->after('desc')->comment('省');
            });
        }

    }

    function _v1_1_7_8(){
        if(!Schema::hasTable('china_areas')) {
            UnpreparedSqlExecute::dispatch('china_areas');
        }
    }

    function _v1_1_7_9(){
        if(!Schema::hasColumn('wx_shop_goods', 'credit_type')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->unsignedTinyInteger('credit_type')->default(1)->after('price')->index('index_5')->comment('货币（0：金币 1：余额）');
            });
        }
        if(!Schema::hasColumn('wx_shop_goods_product', 'credit_type')){
            Schema::table('wx_shop_goods_product', function (Blueprint $table) {
                $table->unsignedTinyInteger('credit_type')->default(1)->after('price')->comment('货币（0：金币 1：余额）');
            });
        }
        if(!Schema::hasColumn('wx_shop_order_goods', 'credit_type')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                $table->unsignedTinyInteger('credit_type')->default(1)->after('price')->comment('货币（0：金币 1：余额）');
            });
        }
        if(!Schema::hasColumn('wx_shop_cart', 'credit_type')){
            Schema::table('wx_shop_cart', function (Blueprint $table) {
                $table->unsignedTinyInteger('credit_type')->default(1)->after('price')->comment('货币（0：金币 1：余额）');
            });
        }
        if(!Schema::hasColumn('wx_shop_order', 'goods_amount_coin')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->integer('goods_amount_coin')->default(0)->after('goods_amount')->comment('商品总价(金币)');
                $table->integer('discounts_amount_coin')->default(0)->after('discounts_amount')->comment('优惠金额(金币)');
                $table->integer('order_amount_coin')->default(0)->after('order_amount')->comment('订单总额(金币)');
            });
        }
        if(!Schema::hasColumn('wx_posts', 'swiper_max_height')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->integer('swiper_max_height')->default(0)->after('img_count')->comment('图片最大高度');
            });
        }
    }


    function _v1_1_7_10(){
        if(!Schema::hasColumn('wx_posts', 'posts_title')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('posts_title')->nullable()->after('id')->comment('标题');
            });
            $posts_id = WxPostMetaStr::where('meta_key', 'posts_title')->pluck('post_id')->toArray();
            if($posts_id){
                foreach ($posts_id as $post_id){
                    WxPost::withoutSyncingToSearch(function () use ($post_id){
                        $posts_title = get_post_meta($post_id, 'posts_title', 's');
                        if($posts_title){
                            WxPost::where('id', $post_id)->update([
                                'posts_title' => $posts_title
                            ]);
                        }
                    });
                }
            }
        }
    }

    function _v1_1_7_11(){
        if(!Schema::hasTable('wx_used_good')){
            Schema::create('wx_used_good', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->string('title', 255)->comment('标题');
                $table->string('detail')->comment('内容');

                $table->unsignedBigInteger('classify_id')->default(0)->comment('分类id');

                $table->float('price')->comment('价格');
                $table->float('original_price')->nullable()->comment('原价');

                // 0: 不是 1：是
                $table->unsignedTinyInteger('is_self_pickup')->default(1)->comment('是否自提');
                $table->unsignedTinyInteger('is_express_delivery')->default(0)->comment('是否通过快递');
                $table->float('express_cost')->default(0)->comment('运费');

                $table->text('image_urls')->nullable()->comment('图片数组');

                $table->double('longitude', 10, 6)->nullable()->comment('经度');
                $table->double('latitude', 10, 6)->nullable()->comment('纬度');
                $table->string('address_name')->nullable()->comment('地址名');
                $table->string('address_detailed')->nullable()->comment('地址名');

                $table->string('ip')->nullable()->comment('ip地址');
                $table->string('country')->nullable()->comment('国家');
                $table->string('province')->nullable()->comment('省份');
                $table->string('city')->nullable()->comment('城市');
                $table->string('district')->nullable()->comment('县城');

                // 0：待审核 1: 推送中 2：提前下架 3：交易完成 4：驳回 5: 买家已付款 6:买家已退款 7: 买家待付款 99: 管理员下架
                $table->unsignedTinyInteger('status')->default(0)->comment('状态');
                $table->index(['longitude', 'latitude'], 'index_1');
                $table->timestamps();
            });
        }


        if(!Schema::hasTable('wx_used_comment')){
            Schema::create('wx_used_comment', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('used_good_id')->index('index_1')->comment('闲置商品id');
                $table->unsignedBigInteger('comment_id')->default(0)->index('index_2')->comment('父级id');
                $table->unsignedBigInteger('comment_agent_id')->default(0)->nullable()->comment('回复的用户id');
                $table->string('comment_agent_name')->nullable()->comment('回复的用户名');
                $table->text('comment_content')->comment('评论内容');
                $table->string('comment_img_url')->nullable()->comment('评论图片');

                $table->double('longitude', 10, 6)->nullable()->comment('经度');
                $table->double('latitude', 10, 6)->nullable()->comment('纬度');

                $table->string('ip')->nullable()->comment('ip地址');
                $table->string('country')->nullable()->comment('国家');
                $table->string('province')->nullable()->comment('省份');
                $table->string('city')->nullable()->comment('城市');
                $table->string('district')->nullable()->comment('县城');

                $table->unsignedTinyInteger('comment_state')->default(0)->comment('状态：0:审核中，1:审核通过，2:驳回');

                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wx_used_classify')){
            Schema::create('wx_used_classify', function (Blueprint $table) {
                $table->id();
                $table->string('name')->index('index_0')->comment('名字');
                $table->string('desc')->nullable()->comment('简介');
                $table->string('pic')->nullable()->comment('分类图');
                $table->string('bg_img')->nullable()->comment('背景图');
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wx_user_contact_apply')) {
            Schema::create('wx_user_contact_apply', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('object_id')->index('index_1')->comment('对象id');
                $table->unsignedTinyInteger('is_phone')->default(0)->comment('手机号码');
                $table->unsignedTinyInteger('is_wechat_account')->default(0)->comment('微信号码');
                $table->string('reason')->comment('申请原因');
                $table->string('img')->nullable()->comment('图片');
                $table->string('with_type')->nullable()->comment('附带类型');
                $table->unsignedBigInteger('with_object_id')->default(0)->comment('附带对象id');
                // 申请状态：1、已申请微信 2、已申请手机号 3、已申请微信和手机号
                $table->unsignedTinyInteger('status')->default(0)->comment('状态');
                $table->unsignedBigInteger('chat_id')->default(0)->comment('申请成功chatID');
                $table->timestamps();
            });
        }


        if(!Schema::hasTable('wx_shop_order_coupon')) {
            Schema::create('wx_shop_order_coupon', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedBigInteger('user_id')->comment('用户id');
                $table->unsignedBigInteger('order_id')->comment('订单id');
                $table->string('code')->index('index_1')->comment('自提码');
                $table->string('qrcode')->comment('二维码');
                $table->string('barcode')->comment('条形码');

                $table->unsignedBigInteger('scanner')->nullable()->comment('核销人');
                $table->dateTime('scan_at')->nullable()->comment('核销时间');

                // 0: 待使用 1：已核销 2: 已失效
                $table->unsignedTinyInteger('status')->default(0)->comment('状态');
                $table->timestamps();
                $table->index(['user_id', 'order_id'], 'index_0');
            });
        }

        if(!Schema::hasColumn('wx_chat', 'contact_apply_id')){
            Schema::table('wx_chat', function (Blueprint $table) {
                $table->unsignedBigInteger('contact_apply_id')->nullable()->after('refer_id')->comment('联系信息申请id');
            });
        }


        if(!Schema::hasColumn('wx_refund', 'credit_type')){
            Schema::table('wx_refund', function (Blueprint $table) {
                $table->unsignedTinyInteger('credit_type')->default(1)->after('amount')->comment('货币（0：金币 1：余额）');
            });
        }

        if(!Schema::hasColumn('wx_refund', 'goods_type')){
            Schema::table('wx_refund', function (Blueprint $table) {
                $table->unsignedTinyInteger('goods_type')->default(0)->after('goods_id')->comment('商品类型');;
            });
        }

        if(!Schema::hasColumn('wx_shop_cart', 'goods_type')){
            Schema::table('wx_shop_cart', function (Blueprint $table) {
                $table->unsignedTinyInteger('goods_type')->default(0)->after('id')->comment('商品类型');
            });
            WxShopCart::where('goods_type', 0)->get()->map(function ($v, $k){
                WxShopCart::where('id', $v->id)->update([
                    'goods_type' => WxShopGoods::where('id', $v->goods_id)->value('type')
                ]);
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'seller_user_id')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->unsignedBigInteger('seller_user_id')->default(0)->after('user_id')->comment('销售的用户id');
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'express_type')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->string('express_type')->default('')->nullable()->after('express_no')->comment('物流公司代码');
            });
        }

        // 规定：一个订单里只能全部包含商城商品，或者全部是闲置商品  （0: 商城（包括其他几种类型商品在内，也包括金币商品在内，虽然订单若有金币商品，就仅有该一个商品），6：闲置（只能有闲置）） 7: 组局
        if(!Schema::hasColumn('wx_shop_order', 'order_from')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->unsignedTinyInteger('order_from')->default(0)->after('id')->comment('订单来源');
            });
        }


        if(!(Settings::get('menu_used_parent_id', 0, false, false) > 0) && !(Menu::where('title', '二手系统')->exists()) ){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-umbrella';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  53;
            $admin_menu->title = '二手系统';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_used_parent_id', $parent_id);


            if(!Menu::where('uri', '/used/config')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  0;
                $admin_menu->title = '配置';
                $admin_menu->uri = '/used/config';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/used/classify')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  1;
                $admin_menu->title = '分类';
                $admin_menu->uri = '/used/classify';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/used/good')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  2;
                $admin_menu->title = '物品';
                $admin_menu->uri = '/used/good';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/used/comment')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  3;
                $admin_menu->title = '留言';
                $admin_menu->uri = '/used/comment';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/used/orderGoods')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  4;
                $admin_menu->title = '订单';
                $admin_menu->uri = '/used/orderGoods';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/used/refund')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  5;
                $admin_menu->title = '退款';
                $admin_menu->uri = '/used/refund';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }

    }

    function _v1_1_8_1(){
        if(!Schema::hasColumn('wx_user', 'wechat_account')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('wechat_account')->nullable()->after('email')->comment('微信号');
            });
        }
        if(!Schema::hasTable('wx_pets_comment')){
            Schema::create('wx_pets_comment', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('pet_adoption_id')->index('index_1')->comment('领养id');
                $table->unsignedBigInteger('comment_id')->default(0)->index('index_2')->comment('父级id');
                $table->unsignedBigInteger('comment_agent_id')->default(0)->nullable()->comment('回复的用户id');
                $table->string('comment_agent_name')->nullable()->comment('回复的用户名');
                $table->text('comment_content')->comment('评论内容');
                $table->string('comment_img_url')->nullable()->comment('评论图片');

                $table->double('longitude', 10, 6)->nullable()->comment('经度');
                $table->double('latitude', 10, 6)->nullable()->comment('纬度');

                $table->string('ip')->nullable()->comment('ip地址');
                $table->string('country')->nullable()->comment('国家');
                $table->string('province')->nullable()->comment('省份');
                $table->string('city')->nullable()->comment('城市');
                $table->string('district')->nullable()->comment('县城');

                $table->unsignedTinyInteger('comment_state')->default(0)->comment('状态：0:审核中，1:审核通过，2:驳回');

                $table->timestamps();
            });
        }
    }

    function _v1_1_8_2(){
        if(Settings::get('menu_pets_parent_id', 0) > 0){
            if(!Menu::where('uri', '/pets/comment')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = Settings::get('menu_pets_parent_id', 0);
                $admin_menu->order =  3;
                $admin_menu->title = '留言';
                $admin_menu->uri = '/pets/comment';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }
        }

        if(!Menu::where('uri', '/page_event')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 18;
            $admin_menu->order =  41;
            $admin_menu->title = '页面事件';
            $admin_menu->uri = '/page_event';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasTable('wx_wallpapers_comment')){
            Schema::create('wx_wallpapers_comment', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('wallpaper_id')->index('index_1')->comment('图集id');
                $table->unsignedBigInteger('comment_id')->default(0)->index('index_2')->comment('父级id');
                $table->unsignedBigInteger('comment_agent_id')->default(0)->nullable()->comment('回复的用户id');
                $table->string('comment_agent_name')->nullable()->comment('回复的用户名');
                $table->text('comment_content')->comment('评论内容');
                $table->string('comment_img_url')->nullable()->comment('评论图片');

                $table->double('longitude', 10, 6)->nullable()->comment('经度');
                $table->double('latitude', 10, 6)->nullable()->comment('纬度');

                $table->string('ip')->nullable()->comment('ip地址');
                $table->string('country')->nullable()->comment('国家');
                $table->string('province')->nullable()->comment('省份');
                $table->string('city')->nullable()->comment('城市');
                $table->string('district')->nullable()->comment('县城');

                $table->unsignedTinyInteger('comment_state')->default(0)->comment('状态：0:审核中，1:审核通过，2:驳回');

                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wx_page_event')){
            Schema::create('wx_page_event', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('scene')->comment('场景');
                $table->unsignedBigInteger('scene_id')->nullable()->comment('场景id');
                $table->unsignedTinyInteger('target_type')->default(0)->comment('跳转类型');
                $table->string('target_id')->nullable()->comment('跳转id');
                $table->unsignedInteger('interval')->default(99999)->comment('间隔/分钟');
            });
        }

    }


    function _v1_1_8_3(){

        if(!Menu::where('uri', '/settings/pagefind')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id =60;
            $admin_menu->order = 21;
            $admin_menu->title = '发现';
            $admin_menu->uri = '/settings/pagefind';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasColumn('wx_circle', 'last_publish_at')){
            Schema::table('wx_circle', function (Blueprint $table) {
                $table->timestamp('last_publish_at')->default('2022-12-09 14:18:00')->after('circle_state')->comment('最后发布时间');
            });
        }

        $flag = false;
        if(!Schema::hasTable('wx_used_need')) {
            $flag = true;
        }else if(Schema::hasTable('wx_used_need') && !Schema::hasColumn('wx_used_need', 'created_at')){
            Schema::dropIfExists('wx_used_need');
            $flag = true;
        }

        if($flag){
            if(!Schema::hasTable('wx_used_need')){
                Schema::create('wx_used_need', function (Blueprint $table) {
                    $table->id();
                    $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                    $table->unsignedBigInteger('used_good_id')->index('index_1')->comment('二手商品id');
                    $table->unsignedTinyInteger('status')->default(1)->comment('状态( 1: 想要， 0 不喜欢 )');
                    $table->timestamps();
                });
            }
        }
    }


    function _v1_1_8_5(){
        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_plate'));
        foreach($table_info_columns as $column){
            if($column->Field == 'plate_introduce'){
                $col_type = $column->Type;
                if($col_type == 'varchar(11)'){
                    Schema::table('wx_plate', function (Blueprint $table) {
                        $table->string('plate_introduce', 255)->change();
                    });
                }
                break;
            }
        }
    }

    function _v1_1_8_6(){
        if(!Schema::hasColumn('wx_circle', 'count_circle_posts')){
            Schema::table('wx_circle', function (Blueprint $table) {
                $table->unsignedInteger('count_circle_follow')->default(0)->after('user_id')->comment('圈子成员总数');
                $table->unsignedInteger('count_circle_posts')->default(0)->after('user_id')->comment('圈子笔记总数');
                $table->unsignedInteger('count_pay_content')->default(0)->after('user_id')->comment('付费笔记总数');
                $table->unsignedInteger('count_comment')->default(0)->after('user_id')->comment('评论总数');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'md5')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('md5', 32)->nullable()->after('degree')->comment('md5');
            });
        }
    }

    function _v1_1_8_7(){
        if(!Schema::hasColumn('wx_user', 'real_name')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('real_id_card', 32)->nullable()->after('phone')->comment('身份证号（模糊）');
                $table->string('real_name', 32)->nullable()->after('phone')->comment('真实姓名（模糊）');
            });
        }
    }

    function _v1_1_8_9(){
        if(!Schema::hasColumn('wx_user_plate', 'status')){
            Schema::table('wx_user_plate', function (Blueprint $table) {
                $table->unsignedTinyInteger('status')->default(1)->after('plate_id')->comment('状态(1：正常 2：取消)');
            });
        }
    }

    function _v1_1_8_10(){
        if(!Schema::hasColumn('wx_user_online', 'device_model')){
            Schema::table('wx_user_online', function (Blueprint $table) {
                $table->string('device_model')->after('device')->default('')->comment('设备型号');
                $table->string('system')->after('device')->default('')->comment('操作系统名称及版本');
            });
        }
        if(!Schema::hasColumn('wx_user_online', 'wifi_mac_address')){
            Schema::table('wx_user_online', function (Blueprint $table) {
                $table->string('wifi_mac_address')->after('device')->default('')->comment('wifi Mac地址');
            });
        }

    }

    function _v1_1_8_11(){
        if(!Schema::hasTable('wx_shop_guarantee_record')){
            Schema::create('wx_shop_guarantee_record', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('shop_id')->index('index_0')->comment('店铺id');
                $table->float('num')->comment('变动数量');
                $table->string('title')->comment('标题');
                $table->timestamps();
            });
        }

        if(!Schema::hasColumn('admin_users', 'uid')){
            Schema::table('admin_users', function (Blueprint $table) {
                $table->unsignedBigInteger('uid')->after('avatar')->nullable()->index('index_1')->comment('用户id');
            });
        }

        Menu::all()->map(function ($v){
            if(!(DB::table('admin_permission_menu')->where('menu_id', $v->id)->exists())){
                DB::beginTransaction();
                try {
                    // todo:
                    $perssion_name = $v->title;
                    if($v->parent_id && $v->parent_id > 0){
                        $menu_father = Menu::find($v->parent_id);
                        if($menu_father){
                            $perssion_name = $menu_father->title.'-' . $perssion_name;
                            if($menu_father->parent_id && $menu_father->parent_id > 0){
                                $menu_gurand_father = Menu::find($menu_father->parent_id);
                                if($menu_gurand_father){
                                    $perssion_name = $menu_gurand_father->title.'-' . $perssion_name;
                                }
                            }
                        }
                    }


                    $http_path = $v->uri.'*';
                    foreach (['settings', 'realtime'] as $special){
                        if(strpos($v->uri, $special.'/') !== false){
                            $uri_arr = explode('/', $v->uri);
                            if(count($uri_arr) == 2){
                                $http_path .= ',/'. $uri_arr[0].'/action/'.$uri_arr[1];
                            }else if(count($uri_arr) == 3){
                                if(_empty_($uri_arr[0])){
                                    $http_path .= ',/'. $uri_arr[1].'/action/'.$uri_arr[2];
                                }
                            }
                        }
                    }

                    foreach (['config'] as $special){
                        if(strpos($v->uri, '/'.$special) !== false){
                            $uri_arr = explode('/', $v->uri);
                            if(count($uri_arr) == 2){
                                $http_path .= ',/'. $uri_arr[0].'/action/'.$uri_arr[1];
                            }else if(count($uri_arr) == 3){
                                if(_empty_($uri_arr[0])){
                                    $http_path .= ',/'. $uri_arr[1].'/action/'.$uri_arr[2];
                                }
                            }
                        }
                    }

                    if(Permission::where('http_path','like', '%'. $http_path .'%')->exists()){
                        $permission_id = Permission::where('http_path','like', '%'.$http_path .'%')->value('id');
                        if(!(PermissionMenu::where('permission_id', $permission_id)->where('menu_id', $v->id)->exists())){
                            $pm_model = new PermissionMenu();
                            $pm_model->permission_id = $permission_id;
                            $pm_model->menu_id = $v->id;
                            $pm_model->save();
                        }
                    }else{
                        $perssion = new Permission();
                        $perssion->name = $perssion_name;
                        $perssion->slug =  str_replace('/', '_', $http_path);
                        $perssion->http_method = null;
                        $perssion->http_path = $http_path;
                        $perssion->order = 47;
                        $perssion->parent_id = 0;
                        $perssion->save();
                        $p_id = $perssion->id;

                        $pm_model = new PermissionMenu();
                        $pm_model->permission_id = $p_id;
                        $pm_model->menu_id = $v->id;
                        $pm_model->save();
                    }

                    DB::commit();
                    return true;
                } catch (\Exception $e) {
                    DB::rollBack();
                    _logger_(__file__, __line__, $e->getMessage());
                    return false;
                }
            }
        });

        if(!Schema::hasColumn('wx_shop_order_goods', 'seller_user_id')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                $table->unsignedBigInteger('seller_user_id')->after('order_id')->nullable()->comment('商家用户');
            });
        }

        if(!Schema::hasColumn('wx_shop_order_after', 'seller_user_id')){
            Schema::table('wx_shop_order_after', function (Blueprint $table) {
                $table->unsignedBigInteger('seller_user_id')->after('user_id')->nullable()->comment('商家用户');
            });
        }

        if(!Schema::hasColumn('wx_shop_cart', 'seller_user_id')){
            Schema::table('wx_shop_cart', function (Blueprint $table) {
                $table->unsignedBigInteger('seller_user_id')->after('user_id')->nullable()->comment('商家用户');
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'serial_platform')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->unsignedTinyInteger('serial_platform')->after('serial_number')->nullable()->comment('支付平台');
            });
        }

        if(!Schema::hasColumn('wx_order', 'order_serial_platform')){
            Schema::table('wx_order', function (Blueprint $table) {
                $table->unsignedTinyInteger('order_serial_platform')->after('order_serial_number')->nullable()->comment('支付平台');
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'parent_order_id')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->unsignedBigInteger('parent_order_id')->after('id')->nullable()->comment('父级订单id');
            });
        }

        if(!Schema::hasTable('wx_shop_follow')){
            Schema::create('wx_shop_follow', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('shop_id')->index('index_1')->comment('店铺id');
                $table->unsignedTinyInteger('status')->default(1)->comment('状态( 1: 关注中， 0 已取消 )');
                $table->timestamps();
            });
        }

    }


    function _v1_1_9_2(){
        if(!AdminSubMenu::where('uri', '/page/settings')->exists() ){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id =0;
            $admin_menu->order = 1017;
            $admin_menu->icon = 'fa-cogs';
            $admin_menu->title = '页面自定义';
            $admin_menu->uri = '/page/settings';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $admin_menu_id = $admin_menu->id;
            Settings::set('sub_menu_page_config_parent_id', $admin_menu_id);
            if(AdminSubMenu::where('uri', '/settings/pageindex')->where('parent_id', 0)->exists()){
                AdminSubMenu::where('uri', '/settings/pageindex')->update(['parent_id'=>$admin_menu_id]);
            }
            if(AdminSubMenu::where('uri', '/settings/publish')->where('parent_id', 0)->exists()){
                AdminSubMenu::where('uri', '/settings/publish')->update(['parent_id'=>$admin_menu_id]);
            }
            if(AdminSubMenu::where('uri', '/settings/circle')->where('parent_id', 0)->exists()){
                AdminSubMenu::where('uri', '/settings/circle')->update(['parent_id'=>$admin_menu_id]);
            }
            if(AdminSubMenu::where('uri', '/settings/ad')->where('parent_id', 0)->exists()){
                AdminSubMenu::where('uri', '/settings/ad')->update(['parent_id'=>$admin_menu_id]);
            }
            if(AdminSubMenu::where('uri', '/settings/post')->where('parent_id', 0)->exists()){
                AdminSubMenu::where('uri', '/settings/post')->update(['parent_id'=>$admin_menu_id]);
            }
        }

        if(!AdminSubMenu::where('uri', '/settings/pagefind')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id = AdminSubMenu::where('uri', '/page/settings')->value('id');
            $admin_menu->order =  1018;
            $admin_menu->icon = 'fa-bullseye';
            $admin_menu->title = '发现页';
            $admin_menu->uri = '/settings/pagefind';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }


    function _v1_1_9_3(){
        if(!Schema::hasColumn('mini_collecter_user_map', 'user_unique1')){
            Schema::table('mini_collecter_user_map', function (Blueprint $table) {
                $table->string('user_unique9', 255)->after('user_unique')->nullable()->index('index_9')->comment('唯一值9');
                $table->string('user_unique8', 255)->after('user_unique')->nullable()->index('index_8')->comment('唯一值8');
                $table->string('user_unique7', 255)->after('user_unique')->nullable()->index('index_7')->comment('唯一值7');
                $table->string('user_unique6', 255)->after('user_unique')->nullable()->index('index_6')->comment('唯一值6');
                $table->string('user_unique5', 255)->after('user_unique')->nullable()->index('index_5')->comment('唯一值5');
                $table->string('user_unique4', 255)->after('user_unique')->nullable()->index('index_4')->comment('唯一值4');
                $table->string('user_unique3', 255)->after('user_unique')->nullable()->index('index_3')->comment('唯一值3');
                $table->string('user_unique2', 255)->after('user_unique')->nullable()->index('index_2')->comment('唯一值2');
                $table->string('user_unique1', 255)->after('user_unique')->nullable()->index('index_1')->comment('唯一值1');
            });
        }
    }

    function _v1_1_9_4(){
        if(!Schema::hasColumn('wx_posts', 'useds')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('useds', 100)->after('tags_id')->nullable()->comment('闲置商品');
            });
        }

        if(!Menu::where('uri', '/settings/pagesearch')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id =60;
            $admin_menu->order = 22;
            $admin_menu->title = '搜索';
            $admin_menu->uri = '/settings/pagesearch';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!AdminSubMenu::where('uri', '/settings/pagesearch')->exists()){
            $admin_menu = new AdminSubMenu();
            $admin_menu->parent_id = AdminSubMenu::where('uri', '/page/settings')->value('id');
            $admin_menu->order =  1019;
            $admin_menu->icon = 'fa-search';
            $admin_menu->title = '搜索页';
            $admin_menu->uri = '/settings/pagesearch';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    function _v1_1_9_5(){
        if(!Permission::where('http_path', 'select/users*')->exists()){
            $perssion = new Permission();
            $perssion->name = '选择任意用户';
            $perssion->slug =  'select_users';
            $perssion->http_method = null;
            $perssion->http_path = 'select/users*';
            $perssion->order = 48;
            $perssion->parent_id = 0;
            $perssion->save();
        }

        if(!Permission::where('http_path', 'select/tags*')->exists()){
            $perssion = new Permission();
            $perssion->name = '选择任意话题';
            $perssion->slug =  'select_tags';
            $perssion->http_method = null;
            $perssion->http_path = 'select/tags*';
            $perssion->order = 49;
            $perssion->parent_id = 0;
            $perssion->save();
        }

        if(!Permission::where('http_path', 'select/shop/goods*')->exists()){
            $perssion = new Permission();
            $perssion->name = '选择任意商品';
            $perssion->slug =  'select_shop_goods';
            $perssion->http_method = null;
            $perssion->http_path = 'select/shop/goods*';
            $perssion->order = 50;
            $perssion->parent_id = 0;
            $perssion->save();
        }

        if(!Permission::where('http_path', 'select/posts/address*')->exists()){
            $perssion = new Permission();
            $perssion->name = '选择任意地址';
            $perssion->slug =  'select_posts_address';
            $perssion->http_method = null;
            $perssion->http_path = 'select/posts/address*';
            $perssion->order = 51;
            $perssion->parent_id = 0;
            $perssion->save();
        }
    }

    function _v1_1_9_7(){
        if(!Schema::hasColumn('wx_used_classify', 'order')){
            Schema::table('wx_used_classify', function (Blueprint $table) {
                $table->unsignedInteger('order')->after('id')->default(0)->comment('排序');
                $table->unsignedTinyInteger('status')->after('bg_img')->default(1)->comment('状态（1正常）');
            });
        }
    }

    function _v1_1_9_8(){
        Menu::where('uri', 'tags')->where('title', '标签')->update(['title'=>'话题']);
    }

    function _v1_1_9_10(){

        $table_info_columns = DB::select( DB::raw('SHOW COLUMNS FROM wx_posts'));
        foreach($table_info_columns as $column){
            if($column->Field == 'tags_id'){
                $col_type = $column->Type;
                if($col_type == 'int(1)'){
                    Schema::table('wx_posts', function (Blueprint $table) {
                        $table->string('tags_id', 255)->nullable()->change();
                    });
                }
                break;
            }
        }



        if(!Schema::hasColumn('wx_posts', 'files_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('files_id', 255)->after('tags_id')->default('0')->comment('文件id');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'sounds_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('sounds_id', 255)->after('tags_id')->default('0')->comment('录音id');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'video_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->unsignedBigInteger('video_id')->after('tags_id')->nullable()->comment('视频id');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'goods_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->string('goods_id', 255)->after('tags_id')->default('0')->comment('商品id');
            });
        }

        if(!Schema::hasColumn('wx_posts', 'vote_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->unsignedBigInteger('vote_id')->after('tags_id')->nullable()->comment('投票id');
            });
        }

    }


    function _v1_1_9_11(){
        if(!Schema::hasColumn('wx_posts_pay_content', 'is_img')){
            Schema::table('wx_posts_pay_content', function (Blueprint $table) {
                $table->unsignedTinyInteger('is_video')->after('is_file')->default(0)->comment('视频付费');
                $table->unsignedTinyInteger('is_img')->after('is_file')->default(0)->comment('图片付费');
            });
        }

    }

    function _v1_1_9_13(){
        if(!Schema::hasColumn('wx_chat', 'expand_id')){
            Schema::table('wx_chat', function (Blueprint $table) {
                $table->unsignedBigInteger('expand_id')->after('chat_audio_length')->default(0)->comment('扩展id');
                // 0: 普通 1:refer_id（转发id）  2：contact_apply_id（联系信息申请id） 3：adoption_apply_id（领养id） 4：shop_good_id（商品id） 5：used_good_id（二手商品id）
                // 101: 笔记审核 102：评论审核 103：组局审核 104：选票审核 105：选手审核 106：闲置审核 107：圈子审核 108：学生认证审核 109：身份认证审核 110：俱乐部审核
                $table->unsignedTinyInteger('expand_type')->after('chat_audio_length')->default(0)->comment('扩展类型');
            });
        }
    }

    function _v1_1_9_14(){

        if (! Schema::hasTable('wx_captcha_img')) {
            Schema::create('wx_captcha_img', function (Blueprint $table) {
                $table->id();
                $table->string('md5', 32)->index('index_0')->comment('md5');
                $table->string('img')->comment('图片');
                $table->unsignedTinyInteger('status')->default(1)->comment('状态（1：启用 0关闭）');
//                $table->string('code')->comment('匹配码');
            });
        }

        if(!Menu::where('uri', '/captcha_img')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 18;
            $admin_menu->order =  42;
            $admin_menu->title = '人机验证';
            $admin_menu->uri = '/captcha_img';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }


        if(!Schema::hasTable('wx_object_meta_num')){
            Schema::create('wx_object_meta_num', function (Blueprint $table) {
                $table->id();
                $table->unsignedTinyInteger('object_type')->comment('object_type');
                $table->unsignedBigInteger('object_id')->comment('object_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['object_type','object_id','meta_key'], 'index_0');
            });
        }
        if(!Schema::hasTable('wx_object_meta_str')){
            Schema::create('wx_object_meta_str', function (Blueprint $table) {
                $table->id();
                $table->unsignedTinyInteger('object_type')->comment('object_type');
                $table->unsignedBigInteger('object_id')->comment('object_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['object_type','object_id','meta_key'], 'index_0');
            });
        }


        if(!Schema::hasTable('wx_used_meta_num')){
            Schema::create('wx_used_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('used_id')->comment('used_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['used_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_used_meta_str')){
            Schema::create('wx_used_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('used_id')->comment('used_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['used_id','meta_key'], 'index_0');
            });
        }

    }


    function _v1_1_9_15(){
        if(!Menu::where('uri', '/settings/group_push')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id =60;
            $admin_menu->order = 23;
            $admin_menu->title = '群推送';
            $admin_menu->uri = '/settings/group_push';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
    }

    function _v1_1_9_16(){
        if(!Schema::hasTable('wx_voter_templates')) {
            Schema::create('wx_voter_templates', function (Blueprint $table) {
                $table->id();
                $table->unsignedTinyInteger('status')->default(1)->comment('启用');
                $table->unsignedTinyInteger('recommend')->default(0)->comment('推荐');
                $table->unsignedBigInteger('sort')->default(0)->comment('排序');
                $table->string('name')->comment('模板名称');
                $table->unsignedBigInteger('template_type')->default(0)->comment('模板类型');
                $table->string('cover')->nullable()->comment('封面');
                $table->json('banner')->nullable()->comment('横幅');
                $table->string('main_background_image')->nullable()->comment('主背景图像');
                $table->string('user_background_image')->nullable()->comment('选手背景图像');
                $table->string('background_color', 7)->comment('背景颜色');
                $table->string('text_color', 7)->comment('文本颜色');
                $table->string('main_color', 7)->comment('主要颜色');
                $table->string('button_bg_color', 7)->comment('按钮背景颜色');
                $table->string('button_text_color', 7)->comment('按钮文本颜色');
                $table->string('text_navigation_bar_color', 7)->default('#000000')->comment('导航栏颜色');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wx_voter')) {
            Schema::create('wx_voter', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->string('master_user_avatar')->comment('展示头像');
                $table->string('master_user_name', 30)->comment('展示名字');

                $table->unsignedBigInteger('template_id')->comment('模板id');

                $table->string('title')->comment('标题');
                $table->string('notice')->nullable()->comment('公告');
                $table->longText('content')->comment('内容');
                $table->string('banners', 500)->comment('封面');

                $table->unsignedTinyInteger('is_open_enter')->default(1)->comment('自助报名');
                $table->unsignedTinyInteger('is_exposure')->default(1)->comment('平台曝光');
                $table->unsignedTinyInteger('is_open_vote_comment')->default(1)->comment('开启活动讨论');
                $table->unsignedTinyInteger('is_open_player_comment')->default(1)->comment('开启选手讨论');

                $table->unsignedTinyInteger('is_can_be_anonymous')->default(0)->comment('开启匿名投票');
                $table->unsignedTinyInteger('is_hide_rank')->default(0)->comment('隐藏排行榜');
                $table->unsignedTinyInteger('is_hide_vote_record')->default(0)->comment('隐藏投票记录');
                $table->unsignedTinyInteger('is_hide_player_count')->default(0)->comment('隐藏选手票数');

                $table->string('music_url')->nullable()->comment('音乐地址');
                $table->string('music_name')->nullable()->comment('音乐名字');
                $table->unsignedTinyInteger('is_music_auto')->default(0)->comment('是否自动播放');

                $table->dateTime('start_time')->comment('投票开始时间');
                $table->dateTime('end_time')->comment('投票结束时间');

                $table->dateTime('enter_start_time')->comment('报名开始时间');
                $table->dateTime('enter_end_time')->comment('报名结束时间');

                $table->unsignedTinyInteger('user_day_limit')->default(0)->comment('每天限制次数');
                $table->unsignedTinyInteger('user_total_limit')->default(0)->comment('总次数限制');

                $table->string('player_called', 30)->comment('选手统称');
                $table->string('unit_called', 30)->comment('票称谓');

                $table->string('main_background_image')->nullable()->comment('主背景图像');
                $table->string('user_background_image')->nullable()->comment('选手背景图像');
                $table->string('background_color', 7)->comment('背景颜色');
                $table->string('text_color', 7)->comment('文本颜色');
                $table->string('main_color', 7)->comment('主要颜色');
                $table->string('button_bg_color', 7)->comment('按钮背景颜色');
                $table->string('button_text_color', 7)->comment('按钮文本颜色');
                $table->string('text_navigation_bar_color', 7)->default('#000000')->comment('导航栏颜色');

                $table->unsignedBigInteger('tenant_id')->default(0)->comment('分站id');

                // 0: 审核中 1：推送中
                $table->unsignedTinyInteger('status')->default(0)->comment('状态');

                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wx_voter_player')) {
            Schema::create('wx_voter_player', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('voter_id')->index('index_1')->comment('选票id');
                $table->unsignedBigInteger('relative_id')->index('index_2')->comment('选手展示id');
                $table->string('show_name', 30)->comment('展示名字');
                $table->string('work_name', 30)->nullable()->comment('作品名字');
                $table->string('work_desc', 400)->nullable()->comment('作品描述');
                $table->string('img_urls', 10000)->comment('图片');
                $table->string('video_url')->nullable()->comment('视频地址');
                $table->string('video_cover')->nullable()->comment('视频封面');
                $table->string('contact_text')->nullable()->comment('联系信息');
                // 0: 审核中 1：推送中
                $table->unsignedTinyInteger('status')->default(0)->comment('状态');

                $table->softDeletes();
                $table->timestamps();
            });
        }


        if(!Schema::hasTable('wx_voter_player_ballot')) {
            Schema::create('wx_voter_player_ballot', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('voter_id')->index('index_1')->comment('选票id');
                $table->unsignedBigInteger('player_id')->index('index_2')->comment('选手id');
                $table->unsignedInteger('num')->comment('票数');
                $table->timestamps();
            });
        }


        if(!(Settings::get('menu_voter_parent_id', 0, false, false) > 0) && !(Menu::where('title', '选票系统')->exists()) ) {
            $admin_menu = new Menu();
            $admin_menu->icon = ' fa-trophy';
            $admin_menu->parent_id = 0;
            $admin_menu->order = 54;
            $admin_menu->title = '选票系统';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;
            Settings::set('menu_voter_parent_id', $parent_id);

            if (!Menu::where('uri', '/voter/config')->exists()) {
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order = 0;
                $admin_menu->title = '配置';
                $admin_menu->uri = '/voter/config';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if (!Menu::where('uri', '/voter/template')->exists()) {
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order = 1;
                $admin_menu->title = '模板';
                $admin_menu->uri = '/voter/template';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if (!Menu::where('uri', '/voters')->exists()) {
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order = 2;
                $admin_menu->title = '选票';
                $admin_menu->uri = '/voters';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if (!Menu::where('uri', '/voter/player')->exists()) {
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order = 3;
                $admin_menu->title = '选手';
                $admin_menu->uri = '/voter/player';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }


        if(!Schema::hasColumn('wx_posts', 'voter_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->unsignedBigInteger('voter_id')->after('vote_id')->default(0)->comment('选票id');
            });
        }
    }

    function _v1_1_9_17(){
        if(!Schema::hasTable('wx_shop_contact')) {
            Schema::create('wx_shop_contact', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('user_id')->index('index_0')->comment('用户id');
                $table->unsignedBigInteger('shop_id')->index('index_1')->comment('店铺id');
                $table->unsignedBigInteger('club_id')->nullable()->index('index_2')->comment('俱乐部id');

                $table->string('name')->comment('联系人');
                $table->string('country_code')->default(86)->comment('国家区号');
                $table->string('phone')->comment('联系电话');

                $table->double('longitude', 10, 6)->comment('经度');
                $table->double('latitude', 10, 6)->comment('纬度');

                $table->string('address_name')->comment('地址名称');
                $table->string('address_detail')->comment('地址详细');

                $table->softDeletes();
                $table->timestamps();
            });
        }


        if(!Schema::hasColumn('wx_shop_goods', 'contact_id')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->unsignedBigInteger('contact_id')->nullable()->after('sku')->comment('经营地址');
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'contact_id')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->unsignedBigInteger('contact_id')->nullable()->after('address')->comment('经营地址');
            });
        }

    }

    function _v1_1_9_18(){
        if(!Menu::where('uri', '/user/student_certify')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id =22;
            $admin_menu->order = 11;
            $admin_menu->title = '学生认证';
            $admin_menu->uri = '/user/student_certify';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasTable('wx_university')) {
            Schema::create('wx_university', function (Blueprint $table) {
                $table->string('sid', 12)->unique('index_0')->primary()->comment('学校唯一标识');
                $table->unsignedInteger('order')->default(0)->comment('倒排序');
                $table->string('name', 120)->index('index_1')->comment('学校名字');
                $table->string('charge', 50)->nullable()->comment('主管部门');
                $table->string('location', 60)->nullable()->comment('所在地');
                $table->string('email_suffix', 30)->nullable()->comment('邮箱后缀');
                // 1:本科 2：专科 3：成人高等学校
                $table->unsignedTinyInteger('level')->nullable()->comment('办学层次');
                // 1: 民办 2：不是
                $table->unsignedTinyInteger('private')->nullable()->comment('是否民办');
                $table->unsignedTinyInteger('is_certify')->index('index_2')->comment('是否可被认证');
            });
        }

        if(!Schema::hasTable('wx_user_student_certify')) {
            Schema::create('wx_user_student_certify', function (Blueprint $table) {
                $table->unsignedBigInteger('user_id')->unique('index_0')->primary()->comment('用户id');
                $table->string('sid', 12)->index('index_1')->comment('学校唯一标识');
                $table->string('school', 50)->index('index_2')->comment('学校名字');
                // student
                $table->string('role', 20)->nullable()->comment('学校身份');
                // 入学年份
                $table->string('term', 4)->nullable()->comment('入学年份');
                $table->string('email', 60)->nullable()->comment('学校邮箱');
                $table->string('questions')->nullable()->comment('答对的题目');
                $table->string('picture')->nullable()->comment('证件照片');
                $table->string('picture2')->nullable()->comment('证件照片2');
                $table->string('introduce')->nullable()->comment('说明');
                // 0: 待审核 1：已通过
                $table->unsignedTinyInteger('status')->default(0)->comment('认证状态');
                $table->timestamps();
            });
        }

        if(!Schema::hasColumn('wx_user', 'university')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('university', 50)->nullable()->after('wechat_account')->comment('大学');
            });
        }
    }


    function _v1_1_9_19(){
        if(!Schema::hasColumn('wx_university', 'class_time')){
            Schema::table('wx_university', function (Blueprint $table) {
                $table->string('class_time', 1000)->nullable()->after('email_suffix')->comment('上课时间设定');
            });
        }
    }


    function _v1_1_9_20(){
        if(!Schema::hasColumn('wx_shop_goods', 'guest_present')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                // Last sales time Guest present

                $table->string('guest_present', 255)->nullable()->after('sku')->comment('嘉宾展示');
                $table->string('service_time_end', 8)->nullable()->after('sku')->comment('服务结束时间');
                $table->string('service_time_start', 8)->nullable()->after('sku')->comment('服务开始时间');
                $table->string('service_date_end', 10)->nullable()->after('sku')->comment('服务结束日期');
                $table->string('service_date_start', 10)->nullable()->after('sku')->comment('服务开始日期');

                $table->dateTime('last_sales_at')->default('2099-01-01 00:00:00')->after('state')->comment('自动下架时间');
            });
        }
    }

}
